package zjut.cocouml.editpolicy;

import org.eclipse.gef.commands.Command;
import org.eclipse.gef.requests.CreateConnectionRequest;

import zjut.cocouml.command.CreateUseCaseConnectionCommand;
import zjut.cocouml.model.BActor;
import zjut.cocouml.model.BUseCase;
import zjut.cocouml.model.relationship.UseCaseRelationship;
import zjut.cocouml.part.BUseCasePart;

public class UseCasePolicy extends AppGraphicalNodeEditPolicy{

	@Override
	public Command getConnectionCompleteCommand(CreateConnectionRequest request) {
		
		if (request.getStartCommand() instanceof CreateUseCaseConnectionCommand ) {
			
//			if (request.getTargetEditPart() instanceof BUseCasePart) {
				System.out.println("UseCasePolicy : getConnectionCompleteCommand");
				if (getHost().getModel() instanceof BUseCase) {
					CreateUseCaseConnectionCommand command = (CreateUseCaseConnectionCommand)request.getStartCommand();
					System.out.println("UseCasePolicy : " + getHost().getModel());
					command.setTarget(getHost().getModel());
					return command;
				}
//			}
		}
		
		return null;
	}

	@Override
	public Command getConnectionCreateCommand(CreateConnectionRequest request) {
		
		if (request.getNewObject() instanceof UseCaseRelationship ) {
			System.out.println("UseCasePolicy : getConnectionCreateCommand");
			UseCaseRelationship model = (UseCaseRelationship)request.getNewObject();
			
			CreateUseCaseConnectionCommand command = new CreateUseCaseConnectionCommand();
			command.setConnection(model);
			command.setSource(getHost().getModel());
			
			System.out.println("UseCasePolicy : getConnectionCreateCommand == " + getHost().getModel());
			request.setStartCommand(command);
			
			return command;			
		}
		return null;
	}

}
